def showMaxFactor(num):
    '判断输入的数是否为素数'
    count = num // 2
    while count > 1:
        # 循环除以 count
        if num % count == 0:
            print('%d 的最大公约数为 %d' % (num, count))
            break
        count -= 1
    # 当while结束且没有break时，执行else
    else:
        print('%d 为素数' % num)


try:
    num = int(input('请输入一个正整数:'))
except ValueError as e:
    print(e)
# 只有当try中的语句正常执行，才执行else中的语句
else:
    showMaxFactor(num)

# with,当文件未被使用，自动调用close()方法
try:
    with open('test', 'w') as f:
        for each_line in f:
            print(each_line)
except OSError as e:
    print('文件报错', e)
